const util = require('@yunke/core/util').default;

const formatDate = function (value) {
    return util.formatDate(util.parseDate(value), 'yyyy-MM-dd');
};

const contractRender = function (item) {
    return `<a target='_blank' href='/contract/edit.shtml#/base?id=${item.contract_id}'>${item.contract_code}</a>`;
};

export default {
    contract: {
        title: "合同收入",
        cols: [
            {
                name: '合同编号',
                render: contractRender,
            },
            {
                name: '客户全称',
                key: 'customer_full_name'
            },
            {
                name: '合同性质',
                key: 'property_name'
            },
            {
                name: '合同录入日期',
                render(item) {
                    return formatDate(item.input_date)
                },
            },
            {
                name: '签约金额',
                key: 'sign_amount'
            },
            {
                name: '应结算金额',
                key: 'income_amount'
            },
            {
                name: '已确认收入金额',
                key: 'total_revenue_recognition_amount'
            },
            {
                name: '累计已开票金额',
                key: 'total_invoice_amount'
            },
            {
                name: '累计已回款金额',
                key: 'total_payment_amount'
            },
        ]
    },
    unrecognized: {
        title: "本期待确认收入",
        cols: [
            {
                name: '签约客户',
                key: 'customer_full_name'
            },
            {
                name: '收入项编号',
                key: 'income_code'
            },
            {
                name: '合同编号',
                render: contractRender,
            },
            {
                name: '收入项名称',
                key: 'finance_type_name',
            },
            {
                name: '收入确认方式',
                key: 'recognition_type',
            },
            {
                name: '收入项金额',
                key: 'amount',
            },
            {
                name: '收入开始日期',
                render(item) {
                    return formatDate(item.establish_time)
                },
            },
            {
                name: '权益日期',
                render(item) {
                    return `${formatDate(item.begin_on) || ''}~${formatDate(item.end_on) || ''}`
                },
            },
            {
                name: '已确认收入',
                key: 'total_revenue_recognition_amount'
            },
            {
                name: '待确认收入',
                key: 'revenue_unrecognized_amount'
            },
            {
                name: '未确认收入已发生坏账',
                key: 'unrecognized_bad_debt_amount'
            },
            {
                name: '收入来源',
                key: 'revenue_source'
            }
        ],
    },
    recognized: {
        title: "本期已确认收入",
        cols: [
            {
                name: '签约客户',
                key: 'customer_full_name'
            },
            {
                name: '收入项编号',
                key: 'income_code'
            },
            {
                name: '合同编号',
                render: contractRender,
            },
            {
                name: '收入项名称',
                key: 'finance_type_name',
            },
            {
                name: '收入确认方式',
                key: 'recognition_type',
            },
            {
                name: '收入项金额',
                key: 'amount',
            },
            {
                name: '收入确认开始日期',
                render(item) {
                    return formatDate(item.begin_on)
                },
            },
            {
                name: '租期起止日期',
                render(item) {
                    return formatDate(item.end_on)
                },
            },
            {
                name: '上期累计确认收入',
                key: 'last_total_revenue_recognition_amount',
            },
            {
                name: '本期确认收入',
                key: 'total_revenue_recognition_amount',
            },
            {
                name: '待确认收入',
                key: 'revenue_unrecognized_amount'
            },
            {
                name: '是否关闭',
                render(item) {
                    return item.revenue_close_status === 'unclosed' ? '未关闭' : '已关闭';
                },
            },
            {
                name: '收入来源',
                key: 'revenue_source'
            }
        ]
    },
    closed: {
        title: "已关闭收入",
        cols: [
            {
                name: '财务收入项',
                key: 'finance_type_name'
            },
            {
                name: '确认方式',
                key: 'recognition_type'
            },
            {
                name: '收入项编码',
                key: 'income_code'
            },
            {
                name: '结转开始日期',
                render(item) {
                    return formatDate(item.establish_time)
                },
            },
            {
                name: '权益日期',
                render(item) {
                    return `${formatDate(item.begin_on) || ''}~${formatDate(item.end_on) || ''}`
                },
            },
            {
                name: '收入金额',
                key: 'amount'
            },
            {
                name: '累计已确认金额',
                key: 'total_revenue_recognition_amount'
            },
            {
                name: '未确认金额',
                key: 'revenue_unrecognized_amount'
            },
            {
                name: '未确认收入已发生坏账',
                key: 'unrecognized_bad_debt_amount'
            },
        ]
    },
};
